<?php
define('ROOT_PATH', dirname(dirname(dirname(dirname(__FILE__)))) . '/');
$basename = basename($_SERVER['SCRIPT_FILENAME']);
$basename = explode('.',$basename );
define('CURSCRIPT', reset($basename));
include ROOT_PATH.'inc/class/application.class.php';
application::init();
$post = $_POST;
$uid = $post['uid'];
$money = $post['money'];
$openid=$post['openid'];
$out_trade_no = 'M' . date('YmdHis') . random(16, 1);
$r = DB::insert('paygold_log',
    array(
        'uid' => $uid,
        'out_trade_no' => $out_trade_no,
        'fee' => $money,
        'openid' => $openid,
        'createtime' => TIMESTAMP
    ),
    1);

if ($r > 0) {
    include_once 'wxpay.class.php';
    $wxPay = new WxPay();
    $pay_info = $wxPay->getOrder(
        array(
            'serviceName' => '游戏币',
            'out_trade_no' => $out_trade_no,
            'money' => $money,
            'openid' => $openid
        )
    );
    if ($pay_info) {
        echo json_encode(array('r' => 0, 'pay_info' => $pay_info));
        exit;
    }
}

echo json_encode(array('r' => -1, 'errmsg' => '支付发起失败, 请重新试!'));

?>